package io.adrainty.algorithm.leetcode.lcr;

/**
 * LCR 006. 两数之和 II - 输入有序数组
 * @link <a href="https://leetcode.cn/problems/kLl5u1/">...</a>
 * @author AdRainty
 * @version V1.0.0
 * @since 2024/9/1 下午4:57
 */
public class LCR006 {

    public int[] twoSum(int[] numbers, int target) {
        int left = 0;
        int right = numbers.length - 1;
        while (left < right) {
            int sum = numbers[left] + numbers[right];
            if (sum == target) {
                return new int[]{left , right};
            } else if (sum < target) {
                left++;
            } else {
                right--;
            }
        }
        return new int[]{-1, -1};
    }

}
